package com.kezesong.leasing.controller.admin;


import com.kezesong.leasing.common.ResponseResult;
import com.kezesong.leasing.controller.BaseController;
import com.kezesong.leasing.entity.GoodsColorEntity;
import com.kezesong.leasing.entity.GoodsInfoEntity;
import com.kezesong.leasing.entity.GoodsLogisticsEntity;
import com.kezesong.leasing.entity.GoodsRAMEntity;
import com.kezesong.leasing.service.GoodsColorService;
import com.kezesong.leasing.service.GoodsInfoService;
import com.kezesong.leasing.service.GoodsLogisticsService;
import com.kezesong.leasing.service.GoodsRamService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.Date;
import java.util.Random;

@RestController
@RequestMapping("/admin/mock/")
public class CreateTestDataController extends BaseController {

    @Autowired
    private GoodsInfoService goodsInfoService;

    @Autowired
    private GoodsColorService goodsColorService;

    @Autowired
    private GoodsRamService goodsRamService;

    @Autowired
    private GoodsLogisticsService goodsLogisticsService;

    @GetMapping("/mockDataCreateGoods/{categoryId}")
    @ApiOperation(value = "mockDataCreateGoods", notes = "批量生成某类商品的测试数据")
    public ResponseResult<String> mockDataGoodsInfo1(@PathVariable("categoryId") int categoryId){

        int rows = 0;
        for (int i = 0; i < 1000; i++) {
            GoodsInfoEntity goodsInfoEntity = new GoodsInfoEntity();
            goodsInfoEntity.setGoodsCategoryId(categoryId);
            String goodsName = "测试商品名称"+new Random().toString();
            goodsInfoEntity.setGoodsName(goodsName);
            goodsInfoEntity.setGoodsDescribe("测试商品名称的测试描述"+goodsName);
            goodsInfoEntity.setGoodsFlag("1");
            goodsInfoEntity.setPicture("http://pic.kzs.com/"+goodsName+".jpg");
            goodsInfoEntity.setShowOrder(0);
            goodsInfoEntity.setCreatedTime(new Date());
            goodsInfoEntity.setCreatedBy("sysMockData");
            BigDecimal bigDecimal = new BigDecimal(2999.99);
            goodsInfoEntity.setPrice(bigDecimal);
            rows = goodsInfoService.addGoodsInfo(goodsInfoEntity);
        }



        ResponseResult<String> responseResult = new ResponseResult<>();
        if (rows<=0){
            responseResult  = buildFailedResponse();
        }
        return responseResult;
    }
//
//
    @GetMapping("/mockDataCreateGoodsLogistics")
    @ApiOperation(value = "mockDataCreateGoodsLogistics", notes = "批量生成某类商品的测试数据")
    public ResponseResult<String> mockDataCreateLogistics(){
        int rows = 0;
        for (int i = 3; i < 1000; i++) {
            GoodsLogisticsEntity goodsLogisticsEntity = new GoodsLogisticsEntity();
            goodsLogisticsEntity.setAddress("關東深圳市羅湖區深南東路5001號");
            goodsLogisticsEntity.setGoodsId(i);
            goodsLogisticsEntity.setCreatedBy("systest");
            goodsLogisticsEntity.setStatus(0);
            rows = goodsLogisticsService.addGoodsLogistics(goodsLogisticsEntity);
        }
        ResponseResult<String> responseResult = new ResponseResult<>();
        if (rows<=0){
            responseResult  = buildFailedResponse();
        }
        return responseResult;
    }

    @GetMapping("/mockDataCreateGoodsColor/")
    @ApiOperation(value = "mockDataCreateGoodsColor", notes = "批量生成某类商品的测试数据")
    public ResponseResult<String> mockDataCreateColor(){
        int rows = 0;
        ResponseResult<String> responseResult = new ResponseResult<>();
        for (int i = 3; i < 1000; i++) {
            int goodsId = i;

            GoodsColorEntity goodsColorEntity = new GoodsColorEntity();
            goodsColorEntity.setColorName("白色");
            goodsColorEntity.setGoodsId(goodsId);
            rows = goodsColorService.addGoodsColor(goodsColorEntity);

            goodsColorEntity.setColorName("蓝色");
            goodsColorEntity.setGoodsId(goodsId);
            rows = goodsColorService.addGoodsColor(goodsColorEntity);

            goodsColorEntity.setColorName("褐色");
            goodsColorEntity.setGoodsId(goodsId);
            rows = goodsColorService.addGoodsColor(goodsColorEntity);

            goodsColorEntity.setColorName("红色");
            goodsColorEntity.setGoodsId(goodsId);
            rows = goodsColorService.addGoodsColor(goodsColorEntity);

            goodsColorEntity.setColorName("黑色");
            goodsColorEntity.setGoodsId(goodsId);
            rows = goodsColorService.addGoodsColor(goodsColorEntity);

        }

        if (rows<=0){
            responseResult  = buildFailedResponse();
        }
        return responseResult;
    }


    @GetMapping("/mockDataCreateGoodsRam/")
    @ApiOperation(value = "mockDataCreateRam", notes = "批量生成某类商品的测试数据")
    public ResponseResult<String> mockDataCreateRam( ){
        int rows = 0;
        for (int i = 3; i < 1000; i++) {
            int goodsId = i;
            GoodsRAMEntity goodsRAMEntity = new GoodsRAMEntity();
            goodsRAMEntity.setRamName("128G");
            goodsRAMEntity.setGoodsId(goodsId);
             rows = goodsRamService.addGoodsRAM(goodsRAMEntity);

            goodsRAMEntity.setRamName("256G");
            goodsRAMEntity.setGoodsId(goodsId);
            rows = goodsRamService.addGoodsRAM(goodsRAMEntity);

            goodsRAMEntity.setRamName("64G");
            goodsRAMEntity.setGoodsId(goodsId);
            rows = goodsRamService.addGoodsRAM(goodsRAMEntity);

            goodsRAMEntity.setRamName("512G");
            goodsRAMEntity.setGoodsId(goodsId);
            rows = goodsRamService.addGoodsRAM(goodsRAMEntity);

            goodsRAMEntity.setRamName("1T");
            goodsRAMEntity.setGoodsId(goodsId);
            rows = goodsRamService.addGoodsRAM(goodsRAMEntity);
        }
        ResponseResult<String> responseResult = new ResponseResult<>();
        if (rows<=0){
            responseResult  = buildFailedResponse();
        }
        return responseResult;
    }


}
